<script>
import req from "@/utils/request"

export default {
  name: "Home",
  data() {
    return {
      isCollapse: false,
      asideWidth: '200px',
      getIcon: 'el-icon-s-fold',
      tableData: [],
    }
  },
  mounted() {
    (async () => {
      const res = await req.get('/user/selectAll')
      this.tableData = res.data
      // console.log(this.tableData) //2.
    })()
    // console.log(this.tableData) //1.
  },
  methods: {
    handleCollapse() {
      this.isCollapse = !this.isCollapse
      this.asideWidth = this.isCollapse ? '64px' : '200px'
      this.getIcon = this.isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'
    },
    handleFull() {
      document.documentElement.requestFullscreen()
    }
  },
}
</script>

<template>
  <div>
    <el-container>

      <el-aside :width="asideWidth" style="min-height: 90vh; background-color: #001529">
        <div style="height: 60px; color: white; justify-content: center; display: flex; align-items: center">
          <img src="../assets/img/12.png" alt="" style="width: 40px; height: 40px">
          <span class="logo-title" v-show="!isCollapse">你好，2024</span>
        </div>

        <!--default-active为item指定index属性，则当menu的default-active属性值为某个item的index的值时使该item高亮，router使menu开启路由模式，使点击item后能导航到index的值位置去-->
        <el-menu :collapse="isCollapse" :collapse-transition="false" router style="border: none"
                 background-color="#001529" :default-active="$route.path" text-color="rgba(255,255,255,0.65)">

          <el-menu-item index="/">
            <i class="el-icon-house"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>

          <el-menu-item index="/Element">
            <i class="el-icon-house"></i>
            <span slot="title">仪表盘</span>
          </el-menu-item>

          <el-menu-item index="/Login">
            <i class="el-icon-house"></i>
            <span slot="title">仪表盘</span>
          </el-menu-item>

          <el-menu-item index="/Element">
            <i class="el-icon-house"></i>
            <span slot="title">仪表盘</span>
          </el-menu-item>

          <!--具名插槽:在子组件submenu中定义了template模板为其指定了插槽，插槽名字为title。子组件定义时在title的位置写了-->
          <!--定义了slot插槽，并且定名为title-->
          <el-submenu index="/23">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>信息管理</span>
            </template>
            <el-menu-item index="/54">用户信息</el-menu-item>
            <el-menu-item index="/87">管理员信息</el-menu-item>
            <el-menu-item index="/">学生信息</el-menu-item>
          </el-submenu>

        </el-menu>
      </el-aside>

      <el-container>

        <el-header>

          <i :class="getIcon" @click="handleCollapse" style="font-size: 24px"></i>
          <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-left: 20px">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/Element' }">活动管理</el-breadcrumb-item>
          </el-breadcrumb>

          <div style="flex: 1; display: flex; align-items: center; justify-content: flex-end">
            <i class="el-icon-quanping" style="font-size: 36px" @click="handleFull"></i>
            <el-dropdown placement="bottom">
              <div>
                <span>下拉菜单</span>
              </div>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>个人信息</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item @click.native="$router.push('/login')">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>

        </el-header>

        <el-main>

          <div
              style="display: flex; width: 30%; height: 50px; box-shadow: 2px 0 6px rgba(0,21,41,.35); align-items: center; justify-content: center; margin-bottom: 5px">
            2024，祝你快乐
          </div>

          <div style="display: flex; height: 70vh">
            <el-card style="flex: 2; box-shadow: 2px 0 6px rgba(0,21,41,.35); margin-right: 10px">
              <div slot="header" class="clearfix">
                <span>这是标签卡片</span>
              </div>
              <div>
                2024毕设正式开始
                <div style="margin-top: 20px">
                  <div style="margin: 10px 0"><strong>主题色</strong></div>
                  <el-button type="primary">按钮</el-button>
                  <el-button type="success">按钮</el-button>
                  <el-button type="warning">按钮</el-button>
                  <el-button type="danger">按钮</el-button>
                  <el-button type="info">按钮</el-button>
                </div>
              </div>
            </el-card>

            <el-card style="flex: 2; box-shadow: 2px 0 6px rgba(0,21,41,.35)">
              <div>
                <span>渲染用户的数据</span>
                <el-table :data="tableData">
                  <el-table-column label="ID" prop="id"></el-table-column>
                  <el-table-column label="用户名" prop="username"></el-table-column>
                  <el-table-column label="姓名" prop="name"></el-table-column>
                  <el-table-column label="地址" prop="address"></el-table-column>
                </el-table>
              </div>
            </el-card>
          </div>

        </el-main>

      </el-container>

    </el-container>
  </div>

</template>

<style scoped>
.el-menu >>> .el-menu--inline {
  background-color: #000c17 !important;
}

.el-menu--inline .el-menu-item {
  background-color: #000c17 !important;
  padding-left: 49px !important;
}

.el-menu-item:hover {
  color: #fff !important;
}

.el-submenu__title:hover span {
  color: #fff !important;
}

.el-submenu__title:hover i {
  color: #fff !important;
}

.el-menu-item.is-active {
  background-color: #40a9ff !important;
  border-radius: 5px !important;
  color: #fff !important;
  width: calc(100% - 8px);
  margin-left: 4px;
}

.el-menu-item {
  height: 40px;
  line-height: 40px;

}

.el-submenu >>> .el-submenu__title {
  height: 40px;
  line-height: 40px;

}

/deep/ .el-submenu__icon-arrow {
  margin: -5px;
}

.el-menu--inline .el-menu-item {
  min-width: 0;
}

.el-menu--inline .el-menu-item.is-active {
  padding-left: 45px !important;
}

.el-menu-item.is-active i {
  margin-left: -4px;
}

.el-aside {
  transition: all .3s;
  box-shadow: 2px 0 6px rgba(0, 21, 41, .35);
}

.el-header {
  box-shadow: 2px 0 6px rgba(0, 21, 41, .35);
  display: flex;
  align-items: center;
}

.logo-title {
  font-size: 20px;
  margin-left: 5px;
  transition: all .3s;
}

</style>